package org.LZQ.ShortLink.admin.controller;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.LZQ.ShortLink.admin.common.convention.result.Result;
import org.LZQ.ShortLink.admin.common.convention.result.Results;
import org.LZQ.ShortLink.admin.dto.req.ShortLinkGroupSaveReqDTO;
import org.LZQ.ShortLink.admin.dto.req.ShortLinkGroupSortReqDTO;
import org.LZQ.ShortLink.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import org.LZQ.ShortLink.admin.dto.resp.ShortLinkGroupRespDTO;
import org.LZQ.ShortLink.admin.remote.ShortLinkActualRemoteService;
import org.LZQ.ShortLink.admin.service.GroupService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短链接后管控制层
 */

@RequiredArgsConstructor
@RequestMapping("/api/shortLink/admin/group")
@RestController
public class GroupController {

    @Resource
    private GroupService groupService;
    private final ShortLinkActualRemoteService shortLinkActualRemoteService = new ShortLinkActualRemoteService(){};
    /**
     * 创建短链接分组
     * @param requestParam
     * @return
     */
    @PostMapping("/create")
    public Result<Void> createShortLink(@RequestBody ShortLinkGroupSaveReqDTO requestParam) {
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }
    @PostMapping("/update")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO requestParam) {
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    /**
     * 查询短链接分组集合
     */
    @GetMapping("/count")
    public Result<List<ShortLinkGroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    /**
     * 删除短链接分组
     * @param gid
     * @return
     */
    @DeleteMapping("/delete")
    public Result<Void> deleteShortLink(@RequestParam("gid") String gid) {
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /**
     * 排序短链接分组
     */
    @PostMapping("/sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> requestParam) {
        groupService.sortGroup(requestParam);
        return Results.success();
    }



}
